package com.huli.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import com.baidu.aip.ocr.AipOcr;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.huli.service.IOwnerService;
import com.huli.service.IUserService;
import com.huli.util.IdCardCheck;
import com.huli.utils.Result;
import com.huli.vo.IdCardVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@Slf4j
@Api("百度识图接口")
public class BaiduOcrController {

    @Autowired
    private AipOcr client;

    @Autowired
    ObjectMapper objectMapper;


    @PostMapping("baiduOcr")
    @ApiOperation("百度识图")
    public Result baiduOcr(@RequestParam("path")String path) {
        // 传入可选参数调用接口
        HashMap<String, String> options = new HashMap<>();
        options.put("language_type", "CHN_ENG");
        options.put("detect_direction", "true");
        options.put("detect_language", "true");
        options.put("probability", "true");

        JSONObject jsonObject = client.basicAccurateGeneral(path, options);
        log.info("------------------------文字识别:>{}",jsonObject.toString());
        return Result.successResult(jsonObject.toString(2));
    }

    /**
     *
     * @param url 图片地址
     * @param side 图片正反面 1为正,2为反
     * @return Result
     */
    @PostMapping("IdCardCheck")
    @ApiOperation("身份证识别")
    public Result idCardCheck(@RequestParam("url") String url,@RequestParam("type") Integer side) {
        IdCardVO idCardVO = IdCardCheck.idCardCheck(url, side, client);

        log.info("------------------->身份证识别:{}",idCardVO);
        return Result.successResult(idCardVO);
    }

}
